#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <cassert>
using namespace std;
#define forn(i,n) for(int i=0;i<int(n);++i)
#define dforn(i,n) for(int i=(n)-1;i>=0;--i)
#define forsn(i,s,n) for(int i=s;i<int(n);++i)
#define forall(it,X) for(typeof(X.begin()) it = X.begin(); it != X.end(); ++it)

typedef vector< vector<double> > Mat;



vector<int> gaussElim(Mat& a) {
	int n=a.size();
	assert(n>0);
	forn(i,n) assert(int(a[i].size())==n+1);
    vector<int> perm(n); forn(i,n) perm[i]=i;
	forn(i,n) {
		int mi,mj; double ma=0.0;
		forsn(ni,i,n)forsn(nj,i,n) if (abs(a[ni][nj])>ma) {
			ma=abs(a[ni][nj]); mi=ni; mj=nj;
		}
		if (ma==0.0) {//a is singular
           cout << "GAUSS PANIC" << endl; break;
        } 
        swap(a[i],a[mi]); //swap rows
	    forn(ni,n) swap(a[ni][i],a[ni][mj]); //swap cols
        swap(perm[i],perm[mj]); //update permutation "matrix"
		forsn(ni,i+1,n) {
			forsn(j,i+1,n+1) a[ni][j]-=a[i][j]*a[ni][i]/a[i][i];
			a[ni][i]=0.0;
		}
	}
    return perm;
}

vector<double> solve(Mat& a) {
	vector<int> perm = gaussElim(a);
	int n=a.size(); assert(n>0);
	forn(i,n) assert(int(a[i].size())==n+1);
	vector<double> res(n,0.0);
	dforn(i,n) {
		res[i]=a[i][n];
		forsn(j,i+1,n) res[i]-=a[i][j]*res[j];
		res[i]/=a[i][i];
	}
    vector<double> r(n);
    forn(i,n) r[perm[i]]=res[i];
	return r;
}

int m,n;
Mat d,dt,a;
vector<double> t,t2;

int id(int i, int j) {return i*n+j;}

int main() {
	ifstream in("input.txt");
	ofstream out("output.txt");
	in >> n >> m;
	d=Mat(m, vector<double>(n*n));
	dt=Mat(n*n, vector<double>(m));
	a=Mat(n*n, vector<double>(n*n+1));
	t=vector<double>(m);
	forn(j,m) {
		forn(i,n*n) {
			in >> d[j][i];
			dt[i][j]=d[j][i];
		}
		in >> t[j];
	}
	//a=dt*(d | t)
	forn(i,n*n)forn(j,n*n)forn(k,m) a[i][j]+=dt[i][k]*d[k][j]; 
	forn(i,n*n)forn(k,m) a[i][n*n]+=dt[i][k]*t[k];
	vector<double> v=solve(a);
	Mat im(n, vector<double>(n)); //im contains the result
	forn(i,n)forn(j,n) im[i][j]=v[id(i,j)];
	out << n << endl;
	forn(i,n) {
		forn(j,n) {
			out.precision(20);
			out << (j?" ":"") << 1.0/im[i][j];
		}
		out << endl;
	}
    return 0;
}
